<!--
Copyright (c) 2019-2022, Hossein Moein
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.
* Neither the name of Hossein Moein and/or the DataFrame nor the
  names of its contributors may be used to endorse or promote products
  derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<!DOCTYPE html>
<html>
<body>

<pre style='color:#000000;background:#ffffff;'><span style='color:#696969; '>/*</span>
<span style='color:#696969; '>Copyright (c) 2019-2022, Hossein Moein</span>
<span style='color:#696969; '>All rights reserved.</span>
<span style='color:#696969; '></span>
<span style='color:#696969; '>Redistribution and use in source and binary forms, with or without</span>
<span style='color:#696969; '>modification, are permitted provided that the following conditions are met:</span>
<span style='color:#696969; '>* Redistributions of source code must retain the above copyright</span>
<span style='color:#696969; '>&#xa0;&#xa0;notice, this list of conditions and the following disclaimer.</span>
<span style='color:#696969; '>* Redistributions in binary form must reproduce the above copyright</span>
<span style='color:#696969; '>&#xa0;&#xa0;notice, this list of conditions and the following disclaimer in the</span>
<span style='color:#696969; '>&#xa0;&#xa0;documentation and/or other materials provided with the distribution.</span>
<span style='color:#696969; '>* Neither the name of Hossein Moein and/or the DataFrame nor the</span>
<span style='color:#696969; '>&#xa0;&#xa0;names of its contributors may be used to endorse or promote products</span>
<span style='color:#696969; '>&#xa0;&#xa0;derived from this software without specific prior written permission.</span>
<span style='color:#696969; '></span>
<span style='color:#696969; '>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND</span>
<span style='color:#696969; '>ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span>
<span style='color:#696969; '>WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE</span>
<span style='color:#696969; '>DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY</span>
<span style='color:#696969; '>DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES</span>
<span style='color:#696969; '>(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</span>
<span style='color:#696969; '>LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND</span>
<span style='color:#696969; '>ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
<span style='color:#696969; '>(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
<span style='color:#696969; '>SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<span style='color:#696969; '>*/</span>

<span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#800000; '>&lt;</span><span style='color:#40015a; '>DataFrame/DataFrame.h</span><span style='color:#800000; '>></span><span style='color:#004a43; '>  </span><span style='color:#696969; '>// Main DataFrame header</span>
<span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#800000; '>&lt;</span><span style='color:#40015a; '>DataFrame/DataFrameFinancialVisitors.h</span><span style='color:#800000; '>></span><span style='color:#004a43; '>  </span><span style='color:#696969; '>// Financial algorithms</span>
<span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#800000; '>&lt;</span><span style='color:#40015a; '>DataFrame/DataFrameMLVisitors.h</span><span style='color:#800000; '>></span><span style='color:#004a43; '>  </span><span style='color:#696969; '>// Machine-learning algorithms</span>
<span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#800000; '>&lt;</span><span style='color:#40015a; '>DataFrame/DataFrameStatsVisitors.h</span><span style='color:#800000; '>></span><span style='color:#004a43; '>  </span><span style='color:#696969; '>// Statistical algorithms</span>

<span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#800000; '>&lt;</span><span style='color:#40015a; '>iostream</span><span style='color:#800000; '>></span>

<span style='color:#696969; '>// -----------------------------------------------------------------------------</span>

<span style='color:#696969; '>// DataFrame library is entirely under hmdf name-space</span>
<span style='color:#696969; '>//</span>
<span style='color:#800000; font-weight:bold; '>using</span> <span style='color:#800000; font-weight:bold; '>namespace</span> hmdf<span style='color:#800080; '>;</span>

<span style='color:#696969; '>// A DataFrame with ulong index type</span>
<span style='color:#696969; '>//</span>
<span style='color:#800000; font-weight:bold; '>using</span> ULDataFrame <span style='color:#808030; '>=</span> StdDataFrame<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>unsigned</span> <span style='color:#800000; font-weight:bold; '>long</span><span style='color:#800080; '>></span><span style='color:#800080; '>;</span>

<span style='color:#696969; '>// A DataFrame with string index type</span>
<span style='color:#696969; '>//</span>
<span style='color:#800000; font-weight:bold; '>using</span> StrDataFrame <span style='color:#808030; '>=</span> StdDataFrame<span style='color:#800080; '>&lt;</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>string</span><span style='color:#800080; '>></span><span style='color:#800080; '>;</span>

<span style='color:#696969; '>// This is just some arbitrary type to show how any type could be in DataFrame</span>
<span style='color:#696969; '>//</span>
<span style='color:#800000; font-weight:bold; '>struct</span>  MyData  <span style='color:#800080; '>{</span>
    <span style='color:#800000; font-weight:bold; '>int</span>         i <span style='color:#800080; '>{</span> <span style='color:#008c00; '>10</span> <span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>double</span>      d <span style='color:#800080; '>{</span> <span style='color:#008000; '>5.5</span> <span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>
    <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>string</span> s <span style='color:#800080; '>{</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Boo</span><span style='color:#800000; '>"</span> <span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>

    MyData<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>default</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>

<span style='color:#696969; '>// -----------------------------------------------------------------------------</span>

<span style='color:#696969; '>// The main purpose of this file is to introduce the basic operations of</span>
<span style='color:#696969; '>// of DataFrame. For more advanced operations and a complete list of features</span>
<span style='color:#696969; '>// with code samples, see documentation at:</span>
<span style='color:#696969; '>// "</span><span style='color:#5555dd; '>https://htmlpreview.github.io/?https://github.com/hosseinmoein/DataFrame/blob/master/docs/HTML/DataFrame.html</span><span style='color:#696969; '>"</span>
<span style='color:#696969; '>//</span>
<span style='color:#800000; font-weight:bold; '>int</span> <span style='color:#400000; '>main</span><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>int</span> argc<span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>char</span> <span style='color:#808030; '>*</span>argv<span style='color:#808030; '>[</span><span style='color:#808030; '>]</span><span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span>

    <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>vector</span><span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>unsigned</span> <span style='color:#800000; font-weight:bold; '>long</span><span style='color:#800080; '>></span>  idx_col1 <span style='color:#808030; '>=</span> <span style='color:#800080; '>{</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>2</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>3</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>4</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>5</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>6</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>7</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>8</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>9</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>10</span> <span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>
    <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>vector</span><span style='color:#800080; '>&lt;</span>MyData<span style='color:#800080; '>></span>         mydata_col<span style='color:#808030; '>(</span><span style='color:#008c00; '>10</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>vector</span><span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>int</span><span style='color:#800080; '>></span>            int_col1 <span style='color:#808030; '>=</span> <span style='color:#800080; '>{</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>2</span><span style='color:#808030; '>,</span> <span style='color:#808030; '>-</span><span style='color:#008c00; '>3</span><span style='color:#808030; '>,</span> <span style='color:#808030; '>-</span><span style='color:#008c00; '>4</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>5</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>6</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>7</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>8</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>9</span><span style='color:#808030; '>,</span> <span style='color:#808030; '>-</span><span style='color:#008c00; '>10</span> <span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>
    <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>vector</span><span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#800080; '>></span>         dbl_col1 <span style='color:#808030; '>=</span> <span style='color:#800080; '>{</span> <span style='color:#008000; '>0.01</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>0.02</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>0.03</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>0.03</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>0.05</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>0.06</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>0.03</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>0.08</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>0.09</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>0.03</span> <span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>

    ULDataFrame ul_df1<span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// One way to load data into the DataFrame is one column at a time.</span>
    <span style='color:#696969; '>// A DataFram column could be at most as long as its index column. So, you</span>
    <span style='color:#696969; '>// must load the index first before loading any column</span>
    <span style='color:#696969; '>//</span>
    <span style='color:#696969; '>// Once you load a column or index, the data is moved to DataFrame. The</span>
    <span style='color:#696969; '>// original vectors are now empty. There are other ways of loading data</span>
    <span style='color:#696969; '>// without the move</span>
    <span style='color:#696969; '>//</span>
    ul_df1<span style='color:#808030; '>.</span>load_index<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>move</span><span style='color:#808030; '>(</span>idx_col1<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    ul_df1<span style='color:#808030; '>.</span>load_column<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>dbl_col</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>move</span><span style='color:#808030; '>(</span>dbl_col1<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    ul_df1<span style='color:#808030; '>.</span>load_column<span style='color:#800080; '>&lt;</span>MyData<span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>my_data_col</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>move</span><span style='color:#808030; '>(</span>mydata_col<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    ul_df1<span style='color:#808030; '>.</span>load_column<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>int</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>integers</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>move</span><span style='color:#808030; '>(</span>int_col1<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>vector</span><span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>unsigned</span> <span style='color:#800000; font-weight:bold; '>long</span><span style='color:#800080; '>></span>  idx_col2 <span style='color:#808030; '>=</span> <span style='color:#800080; '>{</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>2</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>3</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>4</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>5</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>6</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>7</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>8</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>9</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>10</span> <span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>
    <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>vector</span><span style='color:#800080; '>&lt;</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>string</span><span style='color:#800080; '>></span>    str_col1 <span style='color:#808030; '>=</span> <span style='color:#800080; '>{</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>A</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>B</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>C</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>D</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>E</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>F</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>G</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>H</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>I</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>J</span><span style='color:#800000; '>"</span> <span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>
    <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>vector</span><span style='color:#800080; '>&lt;</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>string</span><span style='color:#800080; '>></span>    str_col2 <span style='color:#808030; '>=</span> <span style='color:#800080; '>{</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>K</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>H</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>L</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>M</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>N</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>O</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>P</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Q</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>R</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>S</span><span style='color:#800000; '>"</span> <span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>
    <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>vector</span><span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#800080; '>></span>         dbl_col2 <span style='color:#808030; '>=</span> <span style='color:#800080; '>{</span> <span style='color:#008000; '>1.1</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>1.2</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>1.3</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>1.4</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>1.5</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>1.6</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>1.7</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>1.8</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>1.9</span><span style='color:#808030; '>,</span> <span style='color:#008000; '>2.0</span><span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>
    ULDataFrame                 ul_df2<span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Also, you can load data into a DataFrame all at once</span>
    <span style='color:#696969; '>//</span>
    ul_df2<span style='color:#808030; '>.</span>load_data<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>move</span><span style='color:#808030; '>(</span>idx_col2<span style='color:#808030; '>)</span><span style='color:#808030; '>,</span>
                     <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span>make_pair<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>string col</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> str_col1<span style='color:#808030; '>)</span><span style='color:#808030; '>,</span>
                     <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span>make_pair<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>New York</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> str_col2<span style='color:#808030; '>)</span><span style='color:#808030; '>,</span>
                     <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span>make_pair<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>numbers</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> dbl_col2<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    StrDataFrame    ibm_df<span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Also, you can load data into a DataFrame from a file, suporting a few</span>
    <span style='color:#696969; '>// different formats.</span>
    <span style='color:#696969; '>// If the file cannot be found, an exception will be thrown. If the DataFrame</span>
    <span style='color:#696969; '>// test directory is your current directory when running this, it should work</span>
    <span style='color:#696969; '>// fine.</span>
    <span style='color:#696969; '>//</span>
    ibm_df<span style='color:#808030; '>.</span>read<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>data/SHORT_IBM.csv</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> io_format<span style='color:#800080; '>::</span>csv2<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// To access a column, you must know its name (or index) and its type</span>
    <span style='color:#696969; '>//</span>
    <span style='color:#800000; font-weight:bold; '>auto</span>       <span style='color:#808030; '>&amp;</span>str_col_ref <span style='color:#808030; '>=</span> ul_df2<span style='color:#808030; '>.</span>get_column<span style='color:#800080; '>&lt;</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>string</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>string col</span><span style='color:#800000; '>"</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>const</span> <span style='color:#800000; font-weight:bold; '>auto</span> <span style='color:#808030; '>&amp;</span>close_const_ref <span style='color:#808030; '>=</span> ibm_df<span style='color:#808030; '>.</span>get_column<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>IBM_Close</span><span style='color:#800000; '>"</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>const</span> <span style='color:#800000; font-weight:bold; '>auto</span> <span style='color:#808030; '>&amp;</span>index_vec <span style='color:#808030; '>=</span> ibm_df<span style='color:#808030; '>.</span>get_index<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// In case of a "standard" DataFrame (not a view), the columns are returned</span>
    <span style='color:#696969; '>// as a reference to a std::vector of type of that column.</span>
    <span style='color:#696969; '>//</span>
    <span style='color:#800000; font-weight:bold; '>for</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>auto</span> citer <span style='color:#800080; '>:</span> str_col_ref<span style='color:#808030; '>)</span>
        <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>cout</span> <span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span> citer <span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>for</span> <span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>size_t</span> i <span style='color:#808030; '>=</span> <span style='color:#008c00; '>0</span><span style='color:#800080; '>;</span> i <span style='color:#808030; '>&lt;</span> str_col_ref<span style='color:#808030; '>.</span>size<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span> <span style='color:#808030; '>+</span><span style='color:#808030; '>+</span>i<span style='color:#808030; '>)</span>
        <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>cout</span> <span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span> str_col_ref<span style='color:#808030; '>[</span>i<span style='color:#808030; '>]</span> <span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// You can write the data to a file or stdout in a few formats</span>
    <span style='color:#696969; '>// You must specify all the column types, but only once</span>
    <span style='color:#696969; '>// When writing to a file, the file name/path must be create-able.</span>
    <span style='color:#696969; '>//</span>
    ul_df2<span style='color:#808030; '>.</span>write<span style='color:#800080; '>&lt;</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>ostream</span><span style='color:#808030; '>,</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>string</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>double</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>cout</span><span style='color:#808030; '>,</span> io_format<span style='color:#800080; '>::</span>csv2<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    ibm_df<span style='color:#808030; '>.</span>write<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>long</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>/tmp/test.json</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> io_format<span style='color:#800080; '>::</span>json<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// You can sort by one or multiple columns</span>
    <span style='color:#696969; '>// You must specify all the column types, but only once</span>
    <span style='color:#696969; '>//</span>
    <span style='color:#696969; '>// Sort first by the index column in ascending order than by "string col"</span>
    <span style='color:#696969; '>// column in descending order</span>
    <span style='color:#696969; '>//</span>
    ul_df2<span style='color:#808030; '>.</span><span style='color:#603000; '>sort</span><span style='color:#800080; '>&lt;</span>ULDataFrame<span style='color:#800080; '>::</span>IndexType<span style='color:#808030; '>,</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>string</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>double</span><span style='color:#808030; '>,</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>string</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span>DF_INDEX_COL_NAME<span style='color:#808030; '>,</span> sort_spec<span style='color:#800080; '>::</span>ascen<span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>string col</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> sort_spec<span style='color:#800080; '>::</span>desce<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// You could get another DataFrame by selecting on one or multiple columns</span>
    <span style='color:#696969; '>// You must specify all the column types, but only once</span>
    <span style='color:#696969; '>//</span>
    <span style='color:#800000; font-weight:bold; '>auto</span>    functor <span style='color:#808030; '>=</span> <span style='color:#808030; '>[</span><span style='color:#808030; '>]</span><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>const</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>string</span> <span style='color:#808030; '>&amp;</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>const</span> <span style='color:#800000; font-weight:bold; '>double</span> <span style='color:#808030; '>&amp;</span>val<span style='color:#808030; '>)</span><span style='color:#808030; '>-</span><span style='color:#808030; '>></span> <span style='color:#800000; font-weight:bold; '>bool</span> <span style='color:#800080; '>{</span> <span style='color:#800000; font-weight:bold; '>return</span> <span style='color:#808030; '>(</span>val <span style='color:#808030; '>></span> <span style='color:#008000; '>150.0</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span> <span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>auto</span>    above_150_df <span style='color:#808030; '>=</span> ibm_df<span style='color:#808030; '>.</span>get_data_by_sel<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#808030; '>,</span> decltype<span style='color:#808030; '>(</span>functor<span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>double</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>long</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>IBM_Close</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> functor<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Or, you could choose to get a view. See docs for views</span>
    <span style='color:#696969; '>//</span>
    <span style='color:#800000; font-weight:bold; '>auto</span>    above_150_view <span style='color:#808030; '>=</span> ibm_df<span style='color:#808030; '>.</span>get_view_by_sel<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#808030; '>,</span> decltype<span style='color:#808030; '>(</span>functor<span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>double</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>long</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>IBM_Close</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> functor<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// You can get another DataFrame by group-bying on one or multiple columns</span>
    <span style='color:#696969; '>// You must specify only the type(s) of column(s), you are group-bying</span>
    <span style='color:#696969; '>//</span>
    <span style='color:#696969; '>// Group-by column dbl_col, and I am specifying how to summarize the index</span>
    <span style='color:#696969; '>// column and each of the other columns</span>
    <span style='color:#696969; '>//</span>
    <span style='color:#800000; font-weight:bold; '>auto</span>    gb_df <span style='color:#808030; '>=</span> ul_df1<span style='color:#808030; '>.</span>groupby1<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>dbl_col</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span>
                                            LastVisitor<span style='color:#800080; '>&lt;</span>ULDataFrame<span style='color:#800080; '>::</span>IndexType<span style='color:#808030; '>,</span> ULDataFrame<span style='color:#800080; '>::</span>IndexType<span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span>
                                            <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span>make_tuple<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>integers</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>sum_int</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> SumVisitor<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>int</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span>
                                            <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span>make_tuple<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>my_data_col</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>last_my_data</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> LastVisitor<span style='color:#800080; '>&lt;</span>MyData<span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// You can run statistical, financial, ML, … algorithms on one or multiple</span>
    <span style='color:#696969; '>// columns by using visitors. You must specify the column(s) type(s)</span>
    <span style='color:#696969; '>//</span>
    StdVisitor<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#808030; '>,</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>string</span><span style='color:#800080; '>></span>     stdev<span style='color:#800080; '>;</span>
    CorrVisitor<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#808030; '>,</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>string</span><span style='color:#800080; '>></span>    corrl<span style='color:#800080; '>;</span>

    ibm_df<span style='color:#808030; '>.</span>visit<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>IBM_Close</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> stdev<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>cout</span> <span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Standard deviation of IBM close prices: </span><span style='color:#800000; '>"</span>
              <span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span> stdev<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>
              <span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span>

    <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>cout</span> <span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Correlation between IBM open and close prices: </span><span style='color:#800000; '>"</span>
              <span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span> ibm_df<span style='color:#808030; '>.</span>visit<span style='color:#800080; '>&lt;</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>double</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>IBM_Open</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>IBM_Close</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> corrl<span style='color:#808030; '>)</span><span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>
              <span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span>

    <span style='color:#800000; font-weight:bold; '>return</span> <span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span>

<span style='color:#696969; '>// -----------------------------------------------------------------------------</span>

<span style='color:#696969; '>// Local Variables:</span>
<span style='color:#696969; '>// mode:C++</span>
<span style='color:#696969; '>// tab-width:4</span>
<span style='color:#696969; '>// c-basic-offset:4</span>
<span style='color:#696969; '>// End:</span>
</pre>
<!--Created using ToHtml.com on 2021-08-14 13:57:29 UTC -->

</body>
</html>

<!--
Local Variables:
mode:HTML
tab-width:4
c-basic-offset:4
End:
-->
